package com.cskaoyan.controller.mall;

import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.po.MarketBrand;
import com.cskaoyan.service.mall.ProducersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("admin/brand")
public class ProducersController {

    @Autowired
    ProducersService producersService;

    @RequestMapping("list")
    public BaseRespVo producersBrandList(BasePageInfo basePageInfo, String id, String name) {
        CommonData<MarketBrand> commonData = producersService.queryProducersBrandList(basePageInfo, id, name);

        return BaseRespVo.succeed(commonData);
    }

    @RequestMapping("create")
    public BaseRespVo createProducersBrand(@RequestBody MarketBrand marketBrand) {
        MarketBrand marketBrand1 = producersService.createProducersBrand(marketBrand);
        if (marketBrand1 == null) {
            return BaseRespVo.invalidParameter("添加失败！请重试！");
        }
        return BaseRespVo.succeed(marketBrand1);
    }

    @RequestMapping("delete")
    public BaseRespVo deleteProducersBrand(@RequestBody MarketBrand marketBrand) {
        int code = producersService.deleteProducersBrand(marketBrand.getId());
        if (code == 0) {
            return BaseRespVo.invalidParameter("删除失败！请重试！");
        }
        return BaseRespVo.succeed();
    }

    @RequestMapping("update")
    public BaseRespVo updateProducersBrand(@RequestBody MarketBrand marketBrand) {
        MarketBrand marketBrand1 = producersService.updateProducersBrand(marketBrand);
        if (marketBrand1 == null) {
            return BaseRespVo.invalidParameter("修改失败！请重试！");
        }
        return BaseRespVo.succeed(marketBrand1);
    }


}
